package com.shd.edanpei.ui.view;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.shd.edanpei.R;
import com.shd.edanpei.bean.OrderDetailsModel;
import com.shd.edanpei.ui.adapter.ItemOrderInfoAdapter;

/**
 * Created by mc on 2018/9/20.
 * 企业税金订单 订单所需材料
 */

public class EnterpriseDataView extends LinearLayout {

    private OrderDetailsModel model;
    private boolean isGone = true;
    private ItemOrderInfoAdapter mAdapter;
    private TextView tvMore;
    private ImageView ivArrow;


    public EnterpriseDataView(Context context, OrderDetailsModel model) {
        super(context);
        this.model = model;
        initView();
    }


    private void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.order_enterprise_data, this);

        tvMore = findViewById(R.id.tv_more);
        ivArrow = findViewById(R.id.iv_arrow);
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        mAdapter = new ItemOrderInfoAdapter(getContext());
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }

            @Override
            public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
                super.onMeasure(recycler, state, widthSpec, heightSpec);
            }
        });
        recyclerView.setAdapter(mAdapter);
        mAdapter.setNewData(model.getEnterpriseDataList(model.isPrivacy(), isGone));
        tvMore.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                isGone = !isGone;
                mAdapter.setNewData(model.getEnterpriseDataList(model.isPrivacy(), isGone));
                tvMore.setText(isGone ? "查看更多" : "收起更多");
                ivArrow.setImageDrawable(ContextCompat.getDrawable(getContext(), isGone ? R.drawable.ic_pulldown : R.drawable.ic_pullup));

            }
        });
    }
}
